# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: draw_line_util.py
  @time: 2022/7/22 9:17
  @desc:
"""
from matplotlib import pyplot as plt
from scipy.signal import savgol_filter


def plot_curve1(x_data, y_data):
    plt.plot(x_data, y_data, "b")
    plt.xlabel("WaveLength")
    plt.ylabel("Value")
    plt.grid(True)
    plt.show()


# 平滑曲线
def savgol(x_data, y_data):
    plt.plot(x_data, y_data, "k")
    y_smooth = savgol_filter(y_data, 201, 3, mode="nearest")
    plt.plot(x_data, y_smooth, "b")
    plt.xlabel("WaveLength")
    plt.ylabel("Value")
    plt.grid(True)
    plt.show()


def plot_curve2(curve_list, title, x, y, max_x, max_y):
    color = ["r", "m", "c", "y"]
    label = ["0s", "60s", "300s", "10s"]
    plt.figure(figsize=(20, 20), dpi=100)
    fig, ax = plt.subplots()
    ax.set_title(f"{title} P-V curve")
    for i in range(len(curve_list)):
        ax.plot(curve_list[i][0], curve_list[i][1], color[i], label=f"{label[i]}")
        ax.plot([max_x], [max_y], "s")
        ax.text(max_x, max_y, f"{str(max_x)},{str(max_y)}")
        ax.plot([x], [y], "s")
        ax.text(x, y, f"{str(x)},{str(y)}")
        ax.set_xlabel("Voltage")
        ax.set_ylabel("Power")
        ax.grid(True)
        ax.legend()
    plt.savefig(f"{title}.png")
    plt.show()
